unit Class_MOBL_FFJL;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TMOBLFFJL=class(TUniEngine)
  private
    FDATATYPE: string;
  private
    FUNITLINK: string;
    FGZJGIDEX: Integer;
    FGZJGNAME: string;
    FGZJGORDR: Integer;
    FWAGEKJND: Integer;
    FWAGEKJQJ: Integer;
    FWAGEIDEX: Integer;
    FHOLDTYPE: Integer;
    FKJNDKJQJ: Integer;
    FSTAFIDEX: Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property DATATYPE: string read FDATATYPE write FDATATYPE;
    property UNITLINK: string read FUNITLINK write FUNITLINK;
    property GZJGIDEX: Integer read FGZJGIDEX write FGZJGIDEX;
    property GZJGNAME: string read FGZJGNAME write FGZJGNAME;
    property GZJGORDR: Integer read FGZJGORDR write FGZJGORDR;
    property WAGEKJND: Integer read FWAGEKJND write FWAGEKJND;
    property WAGEKJQJ: Integer read FWAGEKJQJ write FWAGEKJQJ;
    property WAGEIDEX: Integer read FWAGEIDEX write FWAGEIDEX;
    property HOLDTYPE: Integer read FHOLDTYPE write FHOLDTYPE;
    property KJNDKJQJ: Integer read FKJNDKJQJ write FKJNDKJQJ;
    property STAFIDEX: Integer read FSTAFIDEX write FSTAFIDEX;
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AMOBLFFJL:TMOBLFFJL):TMOBLFFJL;overload;        
    class procedure CopyIt(AMOBLFFJL:TMOBLFFJL;var Result:TMOBLFFJL);overload;

    class function  ExpSQL(AStafIdex,AUnitLink,AGZJGIDEX,AWAGEKJND,AWAGEKJQJ,AWAGEIDEX,AHOLDTYPE:string):string;
  end;

implementation

{ TMOBLFFJL }
procedure TMOBLFFJL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GZJG_IDEX').Value := GZJGIDEX;
        ParamByName('GZJG_NAME').Value := GZJGNAME;
        ParamByName('GZJG_ORDR').Value := GZJGORDR;
        ParamByName('WAGE_KJND').Value := WAGEKJND;
        ParamByName('WAGE_KJQJ').Value := WAGEKJQJ;
        ParamByName('WAGE_IDEX').Value := WAGEIDEX;
        ParamByName('HOLD_TYPE').Value := HOLDTYPE;
        ParamByName('KJND_KJQJ').Value := KJNDKJQJ; 
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GZJG_IDEX').Value := GZJGIDEX;
        ParamByName('GZJG_NAME').Value := GZJGNAME;
        ParamByName('GZJG_ORDR').Value := GZJGORDR;
        ParamByName('WAGE_KJND').Value := WAGEKJND;
        ParamByName('WAGE_KJQJ').Value := WAGEKJQJ;
        ParamByName('WAGE_IDEX').Value := WAGEIDEX;
        ParamByName('HOLD_TYPE').Value := HOLDTYPE;
        ParamByName('KJND_KJQJ').Value := KJNDKJQJ; 
      end;  
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('GZJG_IDEX').Value := GZJGIDEX;
        ParamByName('WAGE_KJND').Value := WAGEKJND;
        ParamByName('WAGE_KJQJ').Value := WAGEKJQJ;
        ParamByName('WAGE_IDEX').Value := WAGEIDEX;
        ParamByName('HOLD_TYPE').Value := HOLDTYPE;
 
      end;  
    end;
  end;
end;

function TMOBLFFJL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_MOBL_FFJL',['UNIT_LINK',UNITLINK,'GZJG_IDEX',GZJGIDEX,'WAGE_KJND',WAGEKJND,'WAGE_KJQJ',WAGEKJQJ,'WAGE_IDEX',WAGEIDEX,'HOLD_TYPE',HOLDTYPE],AUniConnection);
end;

function TMOBLFFJL.GetNextIdex: Integer;
begin

end;

function TMOBLFFJL.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TMOBLFFJL.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_MOBL_FFJL WHERE   UNIT_LINK=:UNIT_LINK AND GZJG_IDEX=:GZJG_IDEX AND WAGE_KJND=:WAGE_KJND AND WAGE_KJQJ=:WAGE_KJQJ AND WAGE_IDEX=:WAGE_IDEX AND HOLD_TYPE=:HOLD_TYPE';
end;

function TMOBLFFJL.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_MOBL_FFJL'
         +'    ( UNIT_LINK, GZJG_IDEX, GZJG_NAME, GZJG_ORDR, WAGE_KJND'
         +'    , WAGE_KJQJ, WAGE_IDEX, HOLD_TYPE, KJND_KJQJ)'
         +'    VALUES'
         +'    (:UNIT_LINK,:GZJG_IDEX,:GZJG_NAME,:GZJG_ORDR,:WAGE_KJND'
         +'    ,:WAGE_KJQJ,:WAGE_IDEX,:HOLD_TYPE,:KJND_KJQJ)';
end;

function TMOBLFFJL.GetStrsIndex: string;
begin
  Result:=Format('%S-%D-%D-%D-%D-%D',[UNITLINK,GZJGIDEX,WAGEKJND,WAGEKJQJ,WAGEIDEX,HOLDTYPE]);
end;

function TMOBLFFJL.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_MOBL_FFJL SET'
         +'    GZJG_NAME=:GZJG_NAME,'
         +'    GZJG_ORDR=:GZJG_ORDR,'
         +'    KJND_KJQJ=:KJND_KJQJ'
         +'    WHERE UNIT_LINK=:UNIT_LINK'
         +'    AND   GZJG_IDEX=:GZJG_IDEX'
         +'    AND   WAGE_KJND=:WAGE_KJND'
         +'    AND   WAGE_KJQJ=:WAGE_KJQJ'
         +'    AND   WAGE_IDEX=:WAGE_IDEX'
         +'    AND   HOLD_TYPE=:HOLD_TYPE';
end;

constructor TMOBLFFJL.Create;
begin
  DATATYPE:='DATA_FFJL';
end;

destructor TMOBLFFJL.Destroy;
begin

  inherited;
end;

class function TMOBLFFJL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TMOBLFFJL.Create;
  with TMOBLFFJL(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    GZJGIDEX:=AUniQuery.FieldByName('GZJG_IDEX').AsInteger;
    GZJGNAME:=AUniQuery.FieldByName('GZJG_NAME').AsString;
    GZJGORDR:=AUniQuery.FieldByName('GZJG_ORDR').AsInteger;
    WAGEKJND:=AUniQuery.FieldByName('WAGE_KJND').AsInteger;
    WAGEKJQJ:=AUniQuery.FieldByName('WAGE_KJQJ').AsInteger;
    WAGEIDEX:=AUniQuery.FieldByName('WAGE_IDEX').AsInteger;
    HOLDTYPE:=AUniQuery.FieldByName('HOLD_TYPE').AsInteger;
    KJNDKJQJ:=AUniQuery.FieldByName('KJND_KJQJ').AsInteger;
    STAFIDEX:=AUniQuery.FieldByName('STAF_IDEX').AsInteger;
  end;  
end;

class procedure TMOBLFFJL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TMOBLFFJL(Result) do
  begin
    UNITLINK:=AUniQuery.FieldByName('UNIT_LINK').AsString;
    GZJGIDEX:=AUniQuery.FieldByName('GZJG_IDEX').AsInteger;
    GZJGNAME:=AUniQuery.FieldByName('GZJG_NAME').AsString;
    GZJGORDR:=AUniQuery.FieldByName('GZJG_ORDR').AsInteger;
    WAGEKJND:=AUniQuery.FieldByName('WAGE_KJND').AsInteger;
    WAGEKJQJ:=AUniQuery.FieldByName('WAGE_KJQJ').AsInteger;
    WAGEIDEX:=AUniQuery.FieldByName('WAGE_IDEX').AsInteger;
    HOLDTYPE:=AUniQuery.FieldByName('HOLD_TYPE').AsInteger;
    KJNDKJQJ:=AUniQuery.FieldByName('KJND_KJQJ').AsInteger;
    STAFIDEX:=AUniQuery.FieldByName('STAF_IDEX').AsInteger;
  end;  
end;

class function  TMOBLFFJL.CopyIt(AMOBLFFJL: TMOBLFFJL): TMOBLFFJL;
begin
  Result:=TMOBLFFJL.Create;
  TMOBLFFJL.CopyIt(AMOBLFFJL,Result)
end;

class procedure TMOBLFFJL.CopyIt(AMOBLFFJL:TMOBLFFJL;var Result:TMOBLFFJL);
begin
  if Result=nil then Exit;
  Result.UNITLINK:=AMOBLFFJL.UNITLINK;
  Result.GZJGIDEX:=AMOBLFFJL.GZJGIDEX;
  Result.GZJGNAME:=AMOBLFFJL.GZJGNAME;
  Result.GZJGORDR:=AMOBLFFJL.GZJGORDR;
  Result.WAGEKJND:=AMOBLFFJL.WAGEKJND;
  Result.WAGEKJQJ:=AMOBLFFJL.WAGEKJQJ;
  Result.WAGEIDEX:=AMOBLFFJL.WAGEIDEX;
  Result.HOLDTYPE:=AMOBLFFJL.HOLDTYPE;
  Result.KJNDKJQJ:=AMOBLFFJL.KJNDKJQJ;
end;

class function TMOBLFFJL.ExpSQL(AStafIdex,AUnitLink,
  AGZJGIDEX, AWAGEKJND, AWAGEKJQJ, AWAGEIDEX, AHOLDTYPE: string): string;
begin
  Result:='SELECT A.UNIT_LINK,A.GZJG_IDEX,B.GZJG_NAME,B.GZJG_ORDR,A.WAGE_KJND,A.WAGE_KJQJ,A.WAGE_IDEX,A.HOLD_TYPE,A.KJND_KJQJ,A.STAF_IDEX FROM TBL_WAGE_FL A,TBL_GZJG B'
         +'    WHERE 1=1'
         +'    AND A.GZJG_IDEX=B.GZJG_IDEX'
         +'    AND A.UNIT_LINK=B.UNIT_LINK'
         +'    AND A.STAF_IDEX=%S'
         +'    AND A.UNIT_LINK=%S'
         +'    AND A.GZJG_IDEX=%S'
         +'    AND A.HOLD_TYPE=%S';
  Result:=Format(Result,[AStafIdex,QuotedStr(AUnitLink),AGZJGIDEX,AHOLDTYPE]);

  if AWAGEKJND<>'-1' then
  begin
    Result:=Result + Format('    AND A.WAGE_KJND=%S',[AWAGEKJND]);
  end;

  if AWAGEKJQJ<>'-1' then
  begin
    Result:=Result + Format('    AND A.WAGE_KJQJ=%S',[AWAGEKJQJ]);
  end;

  if AWAGEIDEX<>'-1' then
  begin
    Result:=Result + Format('    AND A.WAGE_IDEX=%S',[AWAGEIDEX]);
  end;

  Result:=Result+'    GROUP BY A.UNIT_LINK,A.GZJG_IDEX,B.GZJG_NAME,B.GZJG_ORDR,A.WAGE_KJND,A.WAGE_KJQJ,A.WAGE_IDEX,A.HOLD_TYPE,A.KJND_KJQJ,A.STAF_IDEX';
  Result:=Result+'    ORDER BY B.GZJG_ORDR,A.KJND_KJQJ DESC';
end;

end.

